package com.example.frn.controller;

import cn.hutool.core.bean.BeanUtil;
import com.example.frn.dto.*;
import com.example.frn.entity.Film;
import com.example.frn.entity.RankingList;
import com.example.frn.service.FilmService;
import com.example.frn.service.RankingListService;
import com.example.frn.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/rankingList")
public class RankingListController {
    @Autowired
    private RankingListService rankingListService;
    @PostMapping("save")
    public R save(@RequestBody RankingListInsertDto dto){
        RankingList rankingList = BeanUtil.copyProperties(dto, RankingList.class);
        if(rankingListService.save(rankingList))
            return R.ok(true);
        else return R.error(false);
    }
    @PostMapping("update")
    public R update(@RequestBody RankingListUpdateDto dto){
        RankingList rankingList = BeanUtil.copyProperties(dto, RankingList.class);
        if(rankingListService.updateById(rankingList))
            return R.ok(true);
        else return R.error(false);
    }
    @PostMapping("remove/{id}")
    public R remove(@PathVariable("id") Integer id){
        if(rankingListService.removeById(id))
            return R.ok(true);
        else return R.error(false);
    }
    @GetMapping("detail/{id}")
    public R detail(@PathVariable("id") Integer id){
        return R.ok(rankingListService.getById(id));
    }
    @PostMapping("page")
    public R page(@RequestBody RankingListPageDto dto){
        return R.ok(rankingListService.page(dto));
    }
    @GetMapping("listFilm/{year}/{categoryName}")
    public R list(@PathVariable Integer year,@PathVariable String categoryName){
        return R.ok(rankingListService.list(year,categoryName));
    }

}
